package com.laboratory.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.laboratory.mapper.OperationLogMapper;
import com.laboratory.model.entity.OperationLog;
import com.laboratory.model.vo.operationLog.OperationLogEeVo;
import com.laboratory.model.dto.operationLog.OperationLogQueryDto;
import com.laboratory.service.OperationLogService;
import org.springframework.stereotype.Service;

/**
* @author lucky
* @description 针对表【operation_log(操作日志)】的数据库操作Service实现
* @createDate 2024-04-02 20:10:54
*/
@Service
public class OperationLogServiceImpl extends ServiceImpl<OperationLogMapper, OperationLog>
    implements OperationLogService{

    @Override
    public PageInfo<OperationLog> getAll(Integer pIndex, Integer pSize, OperationLogQueryDto operateLog) {
        // 开启分页
        PageHelper.startPage(pIndex, pSize);

        // 构造条件
        QueryWrapper<OperationLog> qw = new QueryWrapper<>();

        // 判断对象是否为空
        if (ObjectUtil.isNotEmpty(operateLog)) {

            // 用户名
            if (StrUtil.isNotEmpty(operateLog.getUserName())) {
                qw.like("user_name", operateLog.getUserName());
            }

            // 操作模块
            if (StrUtil.isNotEmpty(operateLog.getOperationModule())) {
                qw.like("operation_module", operateLog.getOperationModule());
            }

            // 操作状态
            if (ObjectUtil.isNotEmpty(operateLog.getOperationState())) {
                qw.eq("operation_state", operateLog.getOperationState());
            }
        }

        //根据id倒序
        qw.orderByDesc("id");

        return new PageInfo<>(baseMapper.selectList((qw)));
    }

    @Override
    public void importOperationLog() {
        EasyExcel.write("D:\\操作日志.xlsx", OperationLogEeVo.class).sheet("操作日志").doWrite(baseMapper.selectList(null));
    }

}




